home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12605 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  107 lines

  1. Path: sol.caps.maine.edu!news    
  2. From: aspenc51 <aspenc51@maine.maine.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: ***Newbie Help with arrays and linker errors!!!***
  5. Date: Wed, 20 Mar 1996 15:04:12 -0500
  6. Organization: University of Maine System
  7. Message-ID: <315064BC.287C@maine.maine.edu>
  8. NNTP-Posting-Host: async11.ts-caps4.caps.maine.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  13.  
  14. I'm just starting to learn programming, and I've run into a sort of block with arrays.  I've got this simple die 
  15. roller that rolls 4 six-sideds and subtracts the lowest of the 4 from the total, and I just can't get it to work.  
  16. I've looked for errors, but there are no complier problems my wrench-in-the-works is a single linker error.  
  17. (undefined symbol 'minimum(int, int)' in module 'diceroll.cpp')  Can someone show me where things are running amuck? 
  18.  This thing's driving me crazy!  Just please e-mail me with your suggestions since my news server kind of only half 
  19. works.
  20.  
  21. Here's the program (written under Borland 4.52 C++)
  22.  
  23. /*        This is a simple die roller program code
  24. **  roll individual dice and total them or
  25. **  4d6 - lowest... it keeps popping up with a fatal linker error
  26. **  that I'm positive is related to the arrays or
  27. **  at least the functions calling arrays*/
  28.  
  29. #include <iostream.h>
  30. #include <iomanip.h>
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33.  
  34. int randadd(int, int);
  35. int minimum(int, int);
  36. int main()
  37. {
  38.     int sides,
  39.          rolls,
  40.          value,
  41.          start;
  42.          value=0;
  43.  
  44.     cout<<"Roll for Character or Single?  1,0"; cin>>start; cout<<endl<<endl;         //really simple menu
  45.     while (start==0)
  46.         {
  47.         cout<<"Enter number of dice "; cin>>rolls; cout<<rolls<<"d"<<endl;
  48.         cout<<" Enter number of sides "; cin>>sides; cout<<rolls<<"d"<<sides<<endl;
  49.  
  50.         value=randadd(rolls, sides);
  51.         cout<<value;
  52.         }
  53.     while (start==-1)           //just stuff to loop and break
  54.         {
  55.         return(0);
  56.         }
  57.     while (start==1)            //character roller
  58.         {
  59.         int counter;
  60.              counter=6;
  61.              while (counter > 0)
  62.                 {
  63.                 counter=counter-1;
  64.                 int roll1=randadd(1, 6),
  65.                      roll2=randadd(1, 6),
  66.                      roll3=randadd(1, 6),
  67.                      roll4=randadd(1, 6),
  68.                      roll_array[4]={roll1, roll2, roll3, roll4};  //4d6 - lowest
  69.  
  70.              value=(roll1+roll2+roll3+roll4)-(minimum(roll_array[4] , 4));  //error seems here
  71.                      cout<<value<<endl;
  72.                 }
  73.                 cin>>start;
  74.                 if (start !=1)
  75.                     return 0;
  76.                 }
  77. }
  78.  
  79. int randadd(int rolls, int sides)            //rolling function
  80. {
  81.         int add;
  82.             add=0;
  83.  
  84.         while(rolls > 0)
  85.             {
  86.             rolls=(rolls-1);
  87.             add=add+(rand() % sides) +1;
  88.             }
  89.      return add;
  90. }
  91.  
  92. int minimum( int roll_array[], int length)        //finds minimum value
  93. {
  94.         int minSoFar;
  95.  
  96.         if (length==1)
  97.                 return roll_array[0];
  98.         else
  99.             {
  100.             minSoFar=minimum(roll_array, length-1);
  101.             if (roll_array[length-1]<minSoFar)
  102.                 return roll_array[length-1];
  103.             else
  104.                 return minSoFar;
  105.             }
  106.  }
  107.